<%@ include file="/webapis/ui/doctype.jspf" %>

<%@ taglib uri="/bbNG" prefix="bbNG"%>
<%@ taglib uri="/bbData" prefix="bbData"%>
<%@ taglib prefix='c' uri="http://java.sun.com/jsp/jstl/core" %>  
<%@ taglib prefix='fmt' uri="http://java.sun.com/jsp/jstl/fmt" %> 

<script src="../dist/js/jquery-3.1.1.min.js" type="text/javascript"></script>

<fmt:setLocale value="${locale}"/> 
<fmt:bundle basename="messages"/>
<bbNG:genericPage>

<bbNG:jsBlock>
<script type="text/javascript">
jQuery.noConflict();
var sourceType = document.getElementsByName("sourceType");
var bbClsName = document.getElementsByName("bbClsName");
var modelClsName = document.getElementsByName("modelClsName");
var rawSourceId = document.getElementsByName("rawSourceId");
var rawDescription = document.getElementsByName("rawDescription");
var mapperAttribute = document.getElementsByName("mapperAttribute");
var renderAttribute = document.getElementsByName("renderAttribute");
var renderRules = document.getElementsByName("renderRules");

function save(){	
	var importParam = "[";
	for(var i = 0; i < sourceType.length; i++){
		var param = {
            "sourceType" : sourceType[i].value,
            "bbClsName" : bbClsName[i].value,
            "modelClsName" : modelClsName[i].value,
            "rawSourceId" : rawSourceId[i].value,
            "rawDescription" : rawDescription[i].value,
            "mapperAttribute" : mapperAttribute[i].value,
            "renderAttribute" : renderAttribute[i].value,
            "renderRules" : renderRules[i].value
	        };
		var obj = JSON.stringify(param);
		importParam+=obj+",";
	}
	importParam = importParam.substring(0, importParam.length-1);
	importParam+="]";
	jQuery.ajax({
    	async: false,
        url: "../datasource/set",    
        contentType:"application/json",   
        dataType: "text",
        type: "POST",
        data:importParam,     
        success: function (result) {
           alert(result);
    },
       error: function (e) {
          alert("failed");
       }
    });
}

</script>
</bbNG:jsBlock>

<bbNG:breadcrumbBar  environment="sys_admin" navItem="admin_main">
<fmt:message key="index" var="index"/>
<bbNG:breadcrumb href="../index">index</bbNG:breadcrumb>
</bbNG:breadcrumbBar>

<bbNG:actionControlBar>
<fmt:message key="set.datasource" var="title"/>
<bbNG:actionButton id="setAction" url="../datasource/load" title="${title}" onClick = "save()" primary="true"/>

</bbNG:actionControlBar>
 
<form id = "listForm" method = "post" action="../datasource/set">
<bbNG:inventoryList collection="${dataSourceModelList}" objectVar="model" className="cn.com.blackboard.DataModule4B2.util.DataSourceModel" url="">

<fmt:message key="set.datasource.sourceType" var="sourceType"/>
<fmt:message key="set.datasource.bbClsName" var="bbClsName"/>
<fmt:message key="set.datasource.modelClsName" var="modelClsName"/>
<fmt:message key="set.datasource.rawSourceId" var="rawSourceId"/>
<fmt:message key="set.datasource.rawDescription" var="rawDescription"/>
<fmt:message key="set.datasource.mapperAttribute" var="mapperAttribute"/>
<fmt:message key="set.datasource.renderAttribute" var="renderAttribute"/>
<fmt:message key="set.datasource.renderRules" var="renderRules"/>

<bbNG:listElement label="${sourceType}" name="sourceType" isRowHeader="true">	
	<input NAME="sourceType"  VALUE="${model.getSourceType().getValue()}">
</bbNG:listElement>

<bbNG:listElement label="${bbClsName}" name="bbClsName">	
	<input NAME="bbClsName"  VALUE="${model.getbBbClsName()}">
</bbNG:listElement>

<bbNG:listElement label="${modelClsName}" name="modelClsName">	
	<input NAME="modelClsName"  VALUE="${model.getModelClsName()}">
</bbNG:listElement>

<bbNG:listElement label="${rawSourceId}" name="rawSourceId">	
	<input NAME="rawSourceId"  VALUE="${model.getRawSourceId()}">
</bbNG:listElement>

<bbNG:listElement label="${rawDescription}" name="rawDescription">	
	<input NAME="rawDescription"  VALUE="${model.getRawDescription()}">
</bbNG:listElement>

<bbNG:listElement label="${mapperAttribute}" name="mapperAttribute">
	<input NAME="mapperAttribute"  VALUE="${model.getMapperAttribute()}">
</bbNG:listElement>

<bbNG:listElement label="${renderAttribute}" name="renderAttribute">
	<input NAME="renderAttribute"  VALUE="${model.getRenderAttribute()}">
</bbNG:listElement>

<bbNG:listElement label="${renderRules}" name="renderRules">
	<input NAME="renderRules"  VALUE="${model.getRenderRules()}">
</bbNG:listElement>

</bbNG:inventoryList>
</form>

<fmt:message key="strButOk" var="strButOk"/>
<bbNG:button id = "refreshBtn" type="PageLevel" label="${strButOk}" url="../index"/>



</bbNG:genericPage>


